package com.g.ocache.event;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

import com.g.ocache.Cache;


/**
 * 
 * @author Jingqi Xu
 */
public class CacheEvent<K, V> {
	//
	private final CacheEventType type;
	
	//
	private K key;
	private V value;
	private V previousValue;
	private Cache<K, V> cache;
	private String description;
	private Exception exception;

	/**
	 * 
	 */
	public CacheEvent(CacheEventType type) {
		this.type = type;
	}
	
	/**
	 * 
	 */
	public String toString() {
		return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
		.append("type", type)
		.append("key", key)
		.append("value", value)
		.append("previousValue", previousValue)
		.append("description", description)
		.append("exception", exception).toString();
	}
	
	/**
	 * 
	 */
	public CacheEventType getType() {
		return type;
	}
	
	public K getKey() {
		return key;
	}

	public void setKey(K key) {
		this.key = key;
	}

	public V getValue() {
		return value;
	}

	public void setValue(V value) {
		this.value = value;
	}
	
	public V getPreviousValue() {
		return previousValue;
	}

	public void setPreviousValue(V previousValue) {
		this.previousValue = previousValue;
	}

	public Cache<K, V> getCache() {
		return cache;
	}

	public void setCache(Cache<K, V> cache) {
		this.cache = cache;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}
	
	public Exception getException() {
		return exception;
	}

	public void setException(Exception exception) {
		this.exception = exception;
	}
}
